package com.pf.business.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.pf.business.enums.BillTypeEnum;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2023/7/15 19:32
 */
public class BillTypeConverter implements Converter<Integer> {

    /**
     * 该方法在导出转换使用
     *
     * @param context
     * @return
     * @throws Exception
     */
    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> context) throws Exception {
        String message = BillTypeEnum.getMessageByCode(context.getValue());
        return new WriteCellData<>(message);
    }

    /**
     * 该方法在导入转换使用
     *
     * @param context
     * @return
     * @throws Exception
     */
    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        String billTypeMsg = context.getReadCellData().getStringValue();
        return BillTypeEnum.getCodeByMessage(billTypeMsg);
    }
}
